<?php 

add_filter('request', 'accs_feed_request');

function setup_future_hook() {
 // Replace native future_post function with replacement
 remove_action('future_post','_future_post_hook');
 remove_action('future_accs_event','_future_accs_event_hook');
 remove_action('future_accs_promo','_future_accs_promo_hook');
 remove_action('future_accs_announcement','_future_accs_announcement_hook');
 
 add_action('future_accs_event','publish_future_post_now');
 add_action('future_accs_promo','publish_future_post_now');
 add_action('future_accs_announcement','publish_future_post_now');
}

function publish_future_post_now($id) {
// Set new post's post_status to "publish" rather than "future."
    wp_publish_post($id);
}

add_action('init', 'setup_future_hook');




function accs_feed_request($qv) {
	if (isset($qv['feed']))
		$qv['post_type'] = get_post_types();
	return $qv;
}

function remove_dashboard_widgets(){
	  global$wp_meta_boxes;
	  unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
	  unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
	  unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
	  unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
	  unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); 
	  unset($wp_meta_boxes['dashboard']['normal']['high']['dashboard_browser_nag']);
	  unset($wp_meta_boxes['dashboard']['normal']['high']['postexcerpt']); 
	 	
}

function remove_post_widgets(){
		//Remove the Excerpt metabox
 		remove_meta_box( 'postexcerpt','accs_announcement','normal' );
 		remove_meta_box( 'postexcerpt','accs_event','normal' );
 		remove_meta_box( 'postexcerpt','accs_promo','normal' );
 		
 		//Remove the Comment metabox
 		remove_meta_box( 'commentsdiv','accs_announcement','normal' );
 		remove_meta_box( 'commentsdiv','accs_event','normal' );
 		remove_meta_box( 'commentsdiv','accs_promo','normal' );

		//Remove the Custom Content metabox
		remove_meta_box( 'postcustom','accs_announcement','normal' );
 		remove_meta_box( 'postcustom','accs_event','normal' );
 		remove_meta_box( 'postcustom','accs_promo','normal' );
 		
 		//Remove the slug metabox
		remove_meta_box( 'slugdiv','accs_announcement','normal' );
 		remove_meta_box( 'slugdiv','accs_event','normal' );
 		remove_meta_box( 'slugdiv','accs_promo','normal' ); 		
 }



function modify_footer_admin () {
  echo 'Created by <a href="http://www.rollins.edu">Rollins College Holt School Computer Science Class, Spring 2012</a>.<br />';
  echo 'Powered by <a href="http://WordPress.org">WordPress</a>.';
}


function custom_right_now_dashboard(){
	if ( is_blog_admin() && current_user_can('edit_posts') ){
		wp_add_dashboard_widget( 'dashboard_right_now', __( 'All Campus Communications Dashboard' ), 'add_custom_right_now' );
		}
}

function add_custom_right_now(){{
	global $wp_registered_sidebars;

	$num_events= wp_count_posts( 'accs_event' );
	$num_announcements= wp_count_posts( 'accs_announcement' );
	$num_promos= wp_count_posts( 'accs_promo' );
	$num_pages = wp_count_posts( 'page' );
	$num_cats  = wp_count_terms('category');
	$num_tags = wp_count_terms('post_tag');

	echo "\n\t".'<div class="table table_content" style="width:40%;">';
	echo "\n\t".'<p class="sub">' . __('Published Content') . '</p>'."\n\t".'<table>';
	echo "\n\t".'<tr class="first">';

	// Events
	$num = number_format_i18n( $num_events->publish );
	$text = _n( 'Event', 'Events', intval($num_events->publish) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php?post_type=accs_event&post_status=publish'>$num</a>";
		$text = "<a href='edit.php?post_type=accs_event&post_status=publish'>$text</a>";
	}
	echo '<td class="first b b-posts">' . $num . '</td>';
	echo '<td class="t posts">' . $text . '</td>';

	echo '</tr><tr>';
	
	// Announcements
	$num = number_format_i18n( $num_announcements->publish );
	$text = _n( 'Announcement', 'Announcements', intval($num_announcements->publish) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php?post_type=accs_announcement&post_status=publish'>$num</a>";
		$text = "<a href='edit.php?post_type=accs_announcement&post_status=publish'>$text</a>";
	}
	echo '<td class="first b b-posts">' . $num . '</td>';
	echo '<td class="t posts">' . $text . '</td>';

	echo '</tr><tr>';

	// Promotions
	$num = number_format_i18n( $num_promos->publish );
	$text = _n( 'Promotion', 'Promotions', intval($num_promos->publish) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php?post_type=accs_promo&post_status=publish'>$num</a>";
		$text = "<a href='edit.php?post_type=accs_promo&post_status=publish'>$text</a>";
	}
	echo '<td class="first b b-posts">' . $num . '</td>';
	echo '<td class="t posts">' . $text . '</td>';

	echo '</tr><tr>';

	echo "</tr>";
	do_action('right_now_content_table_end');
	echo "\n\t</table>\n\t</div>";

	if(current_user_can('manage_options')){
	//Now the pending stuff
	echo "\n\t".'<div class="table table_discussion" style="width:30%;float:left;">';
	echo "\n\t".'<p class="sub">' . __('Pending Approval') . '</p>'."\n\t".'<table>';
	echo "\n\t".'<tr class="first">';
	// Events
	$num = number_format_i18n( $num_events->pending);
	$text = _n( 'Event', 'Events', intval($num_events->pending) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php??post_status=pending&post_type=accs_event'>$num</a>";
		$text = "<a href='edit.php?post_status=pending&post_type=accs_event'>$text</a>";
	}
	echo '<td class="first b b-posts">' . $num . '</td>';
	echo '<td class="t posts">' . $text . '</td>';	echo '</tr><tr>';

	// Announcements
	$num = number_format_i18n( $num_announcements->pending);
	$text = _n( 'Announcement', 'Announcements', intval($num_announcements->pending) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php?post_status=pending&post_type=accs_announcement'>$num</a>";
		$text = "<a href='edit.php?post_status=pending&post_type=accs_announcement'>$text</a>";
	}
	echo '<td class="first b b-posts">' . $num . '</td>';
	echo '<td class="t posts">' . $text . '</td>';
	echo '</tr><tr>';
	// Promotions
	$num = number_format_i18n( $num_promotions->pending);
	$text = _n( 'Promotion', 'Promotions', intval($num_promotions->pending) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php?post_status=pending&post_type=accs_promo'>$num</a>";
		$text = "<a href='edit.php?post_status=pending&post_type=accs_promo'>$text</a>";
	}
	echo '<td class="first b b-posts">' . $num . '</td>';
	echo '<td class="t posts">' . $text . '</td>';
	echo '</tr>';
	do_action('right_now_table_end');
	do_action('right_now_discussion_table_end');
	echo "\n\t</table>\n\t</div>";
}

	//Today's Content
	echo "\n\t".'<div class="table table_discussion" style="width:30%;">';
	echo "\n\t".'<p class="sub">' . __('Todays Events') . '</p>'."\n\t".'<table>';
	echo "\n\t".'<tr class="first">';
	
	$num_events= get_daily_count('accs_event');
	$num_announcements= get_daily_count('accs_announcement');
	$num_promos= get_daily_count('accs_promo');
	$day=date('j');
	
	
	// Events
	$num = number_format_i18n($num_events);
	
	$text = _n( 'Event', 'Events', intval($num_events) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php?post_type=accs_event&day=$day&post_status=publish'>$num</a>";
		$text = "<a href='edit.php?post_type=accs_event&day=$day&post_status=publish'>$text</a>";
	}
	echo '<td class="first b b-posts">' . $num . '</td>';
	echo '<td class="t posts">' . $text . '</td>';	
	echo '</tr><tr>';

	// Announcements
	$num = number_format_i18n( $num_announcements);
	$text = _n( 'Announcement', 'Announcements', intval($num_announcements) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php?post_type=accs_announcement&day=$day&post_status=publish'>$num</a>";
		$text = "<a href='edit.php?post_type=accs_announcement&day=$day&post_status=publish'>$text</a>";
	}
	echo '<td class="first b b-posts">' . $num . '</td>';
	echo '<td class="t posts">' . $text . '</td>';
	echo '</tr><tr>';
	
	// Promotions
	$num = number_format_i18n( $num_promos);
	$text = _n( 'Promotion', 'Promotions', intval($num_promos) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php?post_type=accs_promo&day=$day&post_status=publish'>$num</a>";
		$text = "<a href='edit.php?post_type=accs_promo&day=$day&post_status=publish'>$text</a>";
	}
	echo '<td class="first b b-posts">' . $num . '</td>';
	echo '<td class="t posts">' . $text . '</td>';
	echo '</tr>';
	do_action('right_now_table_end');
	do_action('right_now_discussion_table_end');
	echo "\n\t</table>\n\t</div>";


	
	echo "\n\t".'<div class="versions">';
	$ct = current_theme_info();

	echo "\n\t<p>";

	if ( empty( $ct->stylesheet_dir ) ) {
		if ( ! is_multisite() || is_super_admin() )
			echo '<span class="error-message">' . __('ERROR: The themes directory is either empty or doesn&#8217;t exist. Please check your installation.') . '</span>';
	} elseif ( ! empty($wp_registered_sidebars) ) {
		$sidebars_widgets = wp_get_sidebars_widgets();
		$num_widgets = 0;
		foreach ( (array) $sidebars_widgets as $k => $v ) {
			if ( 'wp_inactive_widgets' == $k || 'orphaned_widgets' == substr( $k, 0, 16 ) )
				continue;
			if ( is_array($v) )
				$num_widgets = $num_widgets + count($v);
		}
		$num = number_format_i18n( $num_widgets );

		$switch_themes = $ct->title;
		if ( current_user_can( 'switch_themes') )
			$switch_themes = '<a href="themes.php">' . $switch_themes . '</a>';
		if ( current_user_can( 'edit_theme_options' ) ) {
			printf(_n('Theme <span class="b">%1$s</span> with <span class="b"><a href="widgets.php">%2$s Widget</a></span>', 'Theme <span class="b">%1$s</span> with <span class="b"><a href="widgets.php">%2$s Widgets</a></span>', $num_widgets), $switch_themes, $num);
		} else {
			printf(_n('Theme <span class="b">%1$s</span> with <span class="b">%2$s Widget</span>', 'Theme <span class="b">%1$s</span> with <span class="b">%2$s Widgets</span>', $num_widgets), $switch_themes, $num);
		}
	} else {
		if ( current_user_can( 'switch_themes' ) )
			printf( __('Theme <span class="b"><a href="themes.php">%1$s</a></span>'), $ct->title );
		else
			printf( __('Theme <span class="b">%1$s</span>'), $ct->title );
	}
	echo '</p>';

	// Check if search engines are blocked.
	if ( !is_network_admin() && !is_user_admin() && current_user_can('manage_options') && '1' != get_option('blog_public') ) {
		$title = apply_filters('privacy_on_link_title', __('Your site is asking search engines not to index its content') );
		$content = apply_filters('privacy_on_link_text', __('Search Engines Blocked') );

		echo "<p><a href='options-privacy.php' title='$title'>$content</a></p>";
	}

	//update_right_now_message();

	echo "\n\t".'<br class="clear" /></div>';
	do_action( 'rightnow_end' );
	do_action( 'activity_box_end' );
	}
}

function get_daily_count($type){
	$current_day = date('j');
	$args = array(
		'post_type' => $type,
		'day'		=> $current_day
	);
	$numposts = get_posts($args);  
	return count($numposts);
}

?>